import urllib.request
import requests, ssl
import re

header = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'
}
cookie = {'BAIDUID': '0DFE30E1D683DC35BBB5610409506455:FG=1',
          'BDRCVFR[-pGxjrCMryR]': 'mk3SLVN4HKm',
          'BIDUPSID': '6D06A616BDF9AE3F29B6A7324892DE9C'}


def paitu(type):
    url = 'https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=result&queryWord={word}&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=-1&z=&ic=0&word={word}&s=&se=&tab=&width=&height=&face=0&istype=2&qc=&nc=1&fr=&cg=girl&pn={pageNum}&rn=60&gsm=1e00000000001e&1490169411926='
    keyword = type
    keyword = urllib.parse.quote(keyword, "utf-8")
    n = 0
    url = url.format(word=keyword, pageNum=str(n))
    request = requests.get(url=url, headers=header, cookies=cookie)
    list_jpg = re.findall('"thumbURL":"(.*?\.jpg)"', request.text)
    list_jpg = set(list_jpg)
    print(request.cookies.items())
    # print('ok')
    # print(list(list_jpg))
    return list(list_jpg)
